<?php
namespace app\index\logic;
use app\common\model\Base;
use think\Db;

class TouzhuList extends Base
{
    //查询投注记录
    public function getBetList($user,$timebh,$czid,$classtz,$sql_tb) {
        $touzhu_array = array();
        if($timebh == 1) {
            $cx_time = strtotime(date('Y-m-d').' 00:00:00'); //今天
        }
        if($timebh == 2) {
            $huoqtime = time() - 24*3600;
            $cx_time = strtotime(date('Y-m-d',$huoqtime).' 00:00:00'); //两天
        }
        if($timebh == 3) {
            $huoqtime = time() - 24*3600*2;
            $cx_time = strtotime(date('Y-m-d',$huoqtime).' 00:00:00'); //三天
        }
        if($timebh == 4) {
            $huoqtime = time() - 24*3600*6;
            $cx_time = strtotime(date('Y-m-d',$huoqtime).' 00:00:00'); //七天
        }
        if($timebh == 5) {
            $huoqtime = time() - 24*3600*14;
            $cx_time = strtotime(date('Y-m-d',$huoqtime).' 00:00:00'); //十五天
        }
        if($timebh == 6) {
            $huoqtime = time() - 24*3600*29;
            $cx_time = strtotime(date('Y-m-d',$huoqtime).' 00:00:00'); //三十天
        }
        if($timebh == '7') {
            $cx_time = 0; //所有
        }
        //投注总数组
        if($czid > 0) {
            $sql_lw = " AND czid={$czid}";
        } else {
            $sql_lw = '';
        }
        
        if($classtz == '0' || $classtz == '1') {
            //未结算
            $jilu_a = Db::name('touzhu_list_no')->alias('tlo')
            ->field('tlo.*,pc.class_name_mini,cl.cp_name_old,cl.cp_name_new')
            ->join('__PLAY_CLASSIFY__ pc','pc.id=tlo.wfid')
            ->join('__CAIPAI_LIST__ cl','cl.id=tlo.czid')
            ->where(" username='{$user}' AND tz_time>'{$cx_time}' {$sql_lw} ")->select();
            $count = 0;
            foreach($jilu_a as $tz) {
                $count += 1;
                $touzhu_array[$count]['class_name_mini'] = $tz['class_name_mini'];
                $touzhu_array[$count]['cp_name_new'] = $tz['cp_name_new'] ? $tz['cp_name_new'] : $tz['cp_name_old'];
                $touzhu_array[$count]['czid'] = $tz['czid'];
                $touzhu_array[$count]['id'] = $tz['id'];
                $touzhu_array[$count]['qihao'] = $tz['qihao'];
                $touzhu_array[$count]['tzhm'] = $tz['tzhm'];
                $touzhu_array[$count]['tzje'] = $tz['tzje'];
                $touzhu_array[$count]['zjje'] = $tz['zjje'];
                $touzhu_array[$count]['wfid'] = $tz['wfid'];
                $touzhu_array[$count]['dqpl'] = $tz['dqpl'];
                $touzhu_array[$count]['xzfd'] = $tz['xzfd'];
                $touzhu_array[$count]['fdje'] = $tz['fdje'];
                $touzhu_array[$count]['kjjg'] = $tz['kjjg'];
                $touzhu_array[$count]['zjzs'] = $tz['zjzs'];
                $touzhu_array[$count]['tz_time'] = $tz['tz_time'];
                $touzhu_array[$count]['class_tz'] = '1';
            }
        }
        
        if($classtz == '0' || $classtz == '2') {
            //已结算
            $jilu_a = Db::name($sql_tb)->alias('tzl')
            ->field('tzl.*,pc.class_name_mini,cl.cp_name_old,cl.cp_name_new')
            ->join('__PLAY_CLASSIFY__ pc','pc.id=tzl.wfid')
            ->join('__CAIPAI_LIST__ cl','cl.id=tzl.czid')
            ->where(" username='{$user}' AND tz_time>'{$cx_time}' {$sql_lw} ")->select();
            $count = count($touzhu_array);
            foreach($jilu_a as $tz) {
                $count += 1;
                $touzhu_array[$count]['class_name_mini'] = $tz['class_name_mini'];
                $touzhu_array[$count]['cp_name_new'] = $tz['cp_name_new'] ? $tz['cp_name_new'] : $tz['cp_name_old'];
                $touzhu_array[$count]['czid'] = $tz['czid'];
                $touzhu_array[$count]['id'] = $tz['id'];
                $touzhu_array[$count]['qihao'] = $tz['qihao'];
                $touzhu_array[$count]['tzhm'] = $tz['tzhm'];
                $touzhu_array[$count]['tzje'] = $tz['tzje'];
                $touzhu_array[$count]['zjje'] = $tz['zjje'];
                $touzhu_array[$count]['wfid'] = $tz['wfid'];
                $touzhu_array[$count]['dqpl'] = $tz['dqpl'];
                $touzhu_array[$count]['xzfd'] = $tz['xzfd'];
                $touzhu_array[$count]['fdje'] = $tz['fdje'];
                $touzhu_array[$count]['kjjg'] = $tz['kjjg'];
                $touzhu_array[$count]['zjzs'] = $tz['zjzs'];
                $touzhu_array[$count]['tz_time'] = $tz['tz_time'];
                $touzhu_array[$count]['class_tz'] = '2';
            }
        }
        
        if($classtz == '0' || $classtz == '5') {
            //追号记录
            $jilu_a = Db::name('touzhu_list_zh')->alias('tlz')
            ->field('tlz.*,pc.class_name_mini,cl.cp_name_old,cl.cp_name_new')
            ->join('__PLAY_CLASSIFY__ pc','pc.id=tlz.wfid')
            ->join('__CAIPAI_LIST__ cl','cl.id=tlz.czid')
            ->where(" username='{$user}' AND tz_time>'{$cx_time}' {$sql_lw} ")->select();
            $count = count($touzhu_array);
            foreach($jilu_a as $tz) {
                $count += 1;
                $touzhu_array[$count]['class_name_mini'] = $tz['class_name_mini'];
                $touzhu_array[$count]['cp_name_new'] = $tz['cp_name_new'] ? $tz['cp_name_new'] : $tz['cp_name_old'];
                $touzhu_array[$count]['czid'] = $tz['czid'];
                $touzhu_array[$count]['id'] = $tz['id'];
                $touzhu_array[$count]['qihao'] = $tz['qihao'];
                $touzhu_array[$count]['tzhm'] = $tz['tzhm'];
                $touzhu_array[$count]['tzje'] = $tz['tzje'];
                $touzhu_array[$count]['zjje'] = $tz['zjje'];
                $touzhu_array[$count]['wfid'] = $tz['wfid'];
                $touzhu_array[$count]['dqpl'] = $tz['dqpl'];
                $touzhu_array[$count]['xzfd'] = $tz['xzfd'];
                $touzhu_array[$count]['fdje'] = $tz['fdje'];
                $touzhu_array[$count]['kjjg'] = $tz['kjjg'];
                $touzhu_array[$count]['zjzs'] = $tz['zjzs'];
                $touzhu_array[$count]['tz_time'] = $tz['tz_time'];
                $touzhu_array[$count]['class_tz'] = '5';
            }
        }


        return $touzhu_array;
    }
    
}